package de.nabble.util;

import java.lang.reflect.Array;
import java.util.ResourceBundle;

import de.nabble.Nabble;

/**
 * Holds some helper methods.
 * @author Tom
 *
 */
public class Helper {
	private Helper(){}
	
	/**
	 * Loads a resource from the given bundle.
	 */
	public static String getResource(String key) {
		ResourceBundle bundle = ResourceBundle.getBundle(Nabble.RESOURCE_PATH);
		return bundle.getString(key).replace("&", "");
	}
	
	/**
	 * Concats two arrays of type T
	 * @param <T> type of the arrayelements
	 * @param clazz class of T. E.g. <code>T.class</code>
	 * @param one first array
	 * @param two second array
	 * @return a new array with elements of one and two.
	 */
	@SuppressWarnings("unchecked")
	public static <T> T[] concatArrays(Class<T> clazz, T[] one, T[] two) {
		
		T[] result = (T[]) Array.newInstance(clazz, one.length + two.length);
		
		int i;
		for(i = 0; i < one.length; i++) {
			result[i] = one[i];
		}
		
		for(int j = 0; j < two.length; j++, i++) {
			
			result[i] = two[j];
		}
		
		return result;
	}

}
